﻿
using EF_coreDemo;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 多对多关系_双向导航
{
    public class MyDbContext : DbContext
    {
        public DbSet<Student> Students { get; set; }
        public DbSet<Teacher> Teachers { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlServer("Server=.;Database=demo5;Trusted_Connection=True;ConnectRetryCount=0;Encrypt=false;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Student>(o =>
            {
                o.ToTable("T_Student");
            });

            modelBuilder.Entity<Teacher>(o =>
            {
                o.ToTable("T_Teacher");
                // o.HasMany(s => s.Students).WithMany(t => t.Teachers).UsingEntity(j => j.ToTable("T_Student_Teacher"));
            });
        }
    }
}
